package com.iris.live.services.data.repositories;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.iris.live.services.data.models.RoleItemModel;
import com.iris.live.services.data.models.RoleItemModelPK;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
public interface RoleItemRepository extends JpaRepository<RoleItemModel, RoleItemModelPK>, JpaSpecificationExecutor<RoleItemModel> {
    @Modifying
    @Query("delete FROM RoleItemModel WHERE permit = ?1")
    int deleteRoleItemByPermit(String permit);

    @Query("select a from RoleItemModel a where a.permit=?1")
    List<RoleItemModel> isSetPermit(String permit);

    @Query("select a from RoleItemModel a where a.permit=?1 and a.itemId=?2")
    List<RoleItemModel> isSetByPermitAndItemId(String permit,Integer itemId);

    @Modifying
    @Query("delete FROM RoleItemModel a WHERE a.permit = ?1 and  a.itemId=?2")
    int deleteRoleItemByPermitAndItemId(String permit ,Integer itemId);
}
